#include"MyClass.hh"

MyClass::MyClass(ClassMate& firstClassMate, ClassMate& secondClassMate){
  head = &firstClassMate;
  tail = &secondClassMate;
  head->m_previousClassMate = nullptr;
  head->m_nextClassMate = &secondClassMate;
  tail->m_previousClassMate = &firstClassMate;
  tail->m_nextClassMate = nullptr;
  size = 2;
}

MyClass::~MyClass(){

}


void MyClass::insert(int position, ClassMate& newMate){
  std::cout<<"Processing insert a newMate at position "<< position << std::endl; 
  ClassMate* left = head;
  ClassMate* right = head->m_nextClassMate;
  for(int i=0; i< position-1; ++i){
     std::cout<<"i = "<< i  << std::endl;  
     left = left->m_nextClassMate;
     right = left->m_nextClassMate;  
  }
  newMate.m_previousClassMate = left; 
  newMate.m_nextClassMate = right; 
  left->m_nextClassMate = &newMate;
  right->m_previousClassMate = &newMate;
  size++;
}

void MyClass::printList(){
  ClassMate* current = head; 
  while(current!=tail){
    current->printInfo();
    current=current->m_nextClassMate; 
  }
  tail->printInfo();

}
